﻿@model Patient
@{
    ViewBag.Title = "编辑患者";
    Layout = "~/Views/Shared/Master.cshtml";
}
@{Html.Telerik().Window().Name("PatientEditWindow").Title("编辑患者").HtmlAttributes(new { @class = "ContentWindow" })
    .Buttons(buttons => buttons.Clear())
    .Content(
@<text>
    @{using (Ajax.BeginForm<PatientController>(c => c.PatientEdit(null),
        new AjaxOptions { OnBegin = "BeforeSend", OnSuccess = "OnSuccess", OnFailure = "OnError" }))
      {
        <table>
            <tr>
                <th>身份证号</th>
                <td>
                    @Html.HiddenFor(model => model.ID)
                    @Html.DisplayFor(model => model.IDCard)
                </td>
            </tr>
            <tr>
                <th>社保号</th>
                <td>@Html.TextBoxFor(model => model.SocialID)</td>
            </tr>
            <tr>
                <th>姓名</th>
                <td>@Html.TextBoxFor(model => model.Name)</td>
            </tr>
            <tr>
                <th>性别</th>
                <td>@Html.GenderEditorFor(model => model.Gender)</td>
            </tr>
            <tr>
                <th>生日</th>
                <td>@Html.DateEditorFor(model => model.Birthday)</td>
            </tr>
            <tr>
                <th>单位</th>
                <td>@Html.TextBoxFor(model => model.Company)</td>
            </tr>
            <tr>
                <th>职业</th>
                <td>@Html.TextBoxFor(model => model.Job)</td>
            </tr>
            <tr>
                <th>地址</th>
                <td>@Html.TextBoxFor(model => model.Address)</td>
            </tr>
            <tr>
                <th>电话</th>
                <td>@Html.TextBoxFor(model => model.Phone)</td>
            </tr>
            <tr>
                <th>出生地</th>
                <td>@Html.TextBoxFor(model => model.BirthPlace)</td>
            </tr>
            <tr>
                <th>婚姻状况</th>
                <td>@Html.TextBoxFor(model => model.Marriage)</td>
            </tr>
        </table>
        <input type="submit" value="提交" />
      }
    }
    </text>)
    .Render();
}
@{Html.Telerik().Window().Modal(true).Visible(false)
    .Name("adding").Title("系统提示")
    .Buttons(buttons => buttons.Close())
    .ClientEvents(window => window.OnOpen("OnAddingOpen"))
    .Content(
@<text>
正在编辑，请稍后...
</text>)
    .Render();
}
@{Html.Telerik().Window().Modal(true).Visible(false)
    .Name("addSuccess").Title("系统提示")
    .Buttons(buttons => buttons.Close())
    .ClientEvents(window => window.OnOpen("OnAddSuccessOpen"))
    .Content(
@<text>
保存成功！
</text>)
    .Render();
}
@{Html.Telerik().Window().Modal(true).Visible(false)
    .Name("addError").Title("系统提示")
    .Buttons(buttons => buttons.Clear())
    .ClientEvents(window => window.OnOpen("OnAddErrorOpen"))
    .Content(
@<text>
出现错误，请重试！
</text>)
    .Render();
}
<script type="text/javascript">
    function OnAddingOpen() {
        $("#adding").data("tWindow").center();

    }
    function OnAddSuccessOpen() {
        $("#addSuccess").data("tWindow").center();

    }
    function OnAddErrorOpen() {
        $("#addError").data("tWindow").center();
    }
    function BeforeSend() {
        $("#adding").data("tWindow").open();
    }

    function OnSuccess(data) {
        if (data.success) {
            $("#addSuccess").data("tWindow").open();
            $("#adding").data("tWindow").close();
            window.location = "@(Url.Action<PatientController>(c => c.PatientDetail(Model.ID)))"
        } else {
            $("#addError").data("tWindow").open();
        }
    }

    function OnError() {
        $("#addError").data("tWindow").open();
        $("#adding").data("tWindow").close();
    }
</script>
